﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UniversalDataAccess;
using System.Configuration;
using UniversalDataAccess.BusinessEntities;

namespace ClientAppWithDirectDataAccess
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            RefreshData();
        }

        private void RefreshData()
        {
            DivisionsDataAccess s = new DivisionsDataAccess("UniversityEntitiesContext", ConfigurationManager.ConnectionStrings["UniversityEntitiesContext"].ConnectionString, true);

             dataGridView1.DataSource = s.SelectTObjectsList();
           // dataGridView1.DataSource = s.SelectDivisionsList();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataAccessBase s = new DataAccessBase("UniversityEntitiesContext", ConfigurationManager.ConnectionStrings["UniversityEntitiesContext"].ConnectionString, true);

           
            TObject t = new TObject();
            t.CLASS_ID = 1;
            //t.EXT_ID = "1";
            //t.ID = 777;
            t.NAME = "___7777__";
            t.PARENT_ID = "0";

            int gen_id = -1;
            s.InsertTObject(t, ref  gen_id);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DataAccessBase s = new DataAccessBase("UniversityEntitiesContext", ConfigurationManager.ConnectionStrings["UniversityEntitiesContext"].ConnectionString, true);

            TObject t = new TObject();
            t.CLASS_ID = 1;
            t.EXT_ID = "1";
            t.ID = 777;
            t.NAME = "(((((__7777__)))";
            t.PARENT_ID = "0";
            s.UpdateTObject(t);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DataAccessBase s = new DataAccessBase("UniversityEntitiesContext", ConfigurationManager.ConnectionStrings["UniversityEntitiesContext"].ConnectionString, true);

            TObject t = new TObject();           
            t.ID = 888;            
            s.DeleteTObject(t);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            RefreshData();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            DivisionsDataAccess s = new DivisionsDataAccess("UniversityEntitiesContext", ConfigurationManager.ConnectionStrings["UniversityEntitiesContext"].ConnectionString, true);

            Division t = new Division();
            t.CLASS_ID = 1;
           // t.EXT_ID = "1";
           // t.ID = 888;
            t.NAME = "___888__";
            t.PARENT_ID = "0";

            t.BOSS_ID = "boss guid";
            t.DATE_CREATED = DateTime.Now;
            t.DESCRIPTION = "ololo";

            int gen_Id = -1;
            s.InsertDivision(t,ref gen_Id);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            DivisionsDataAccess s = new DivisionsDataAccess("UniversityEntitiesContext", ConfigurationManager.ConnectionStrings["UniversityEntitiesContext"].ConnectionString, true);

            Division t = new Division();
            t.CLASS_ID = 1;
            t.EXT_ID = "1";
            t.ID = 888;
            t.NAME = "(((___888__))))";
            t.PARENT_ID = "0";

            t.BOSS_ID = "boss guid";
            t.DATE_CREATED = DateTime.Now;
            t.DESCRIPTION = "ololopopop";

            s.UpdateDivision(t);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            DivisionsDataAccess s = new DivisionsDataAccess("UniversityEntitiesContext", ConfigurationManager.ConnectionStrings["UniversityEntitiesContext"].ConnectionString, true);
            
            Division t = new Division();
            t.ID = 888;
            s.DeleteDivision(t);
        }
    }
}
